package concurrencyPractice.chapter02;

import concurrencyPractice.ThreadSafe;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import java.math.BigInteger;
import java.util.concurrent.atomic.AtomicLong;

/**
 * @author xinya
 * @version 1.0
 * @project javacore
 * @description 程序2-5
 * @date 2023/12/21 17:34:38
 */
@ThreadSafe
public class CountingFactorizer {

    private final AtomicLong count = new AtomicLong();

    public long getCount (){
        return count.get();
    }

    // 原子操作
    public void service(ServletRequest req, ServletResponse resp) {
        BigInteger i = extractFromRequest(req);

        BigInteger[] factors = factor[i];

        count.incrementAndGet();
        encodeIntoResponse(resp, factors);
    }

    private void encodeIntoResponse(ServletResponse resp, BigInteger[] factors) {
    }

    private BigInteger extractFromRequest(ServletRequest req) {
        return null;
    }
}
